/*
*abstract:接收信号发送的数据 信号接收端显示发送过来的数据
*author:张玉行
*email:zhangyuhang2009@gmail.com
*date:2011.10.12
*/

#include <stdio.h>
#include <signal.h>

void handler(int num,siginfo_t *info,void* arg){
	printf("begin\n");
	printf("signum = %d\n",info->si_signo);
	printf("si_ptr = %d\n",info->si_int);
	sleep(5);
	printf("end\n");
}

int main( int argc,char* argv[]){
printf("pid = %d\n",getpid());
	sigset_t newmask,oldmask;
	struct sigaction act;
	sigemptyset(&act.sa_mask);
	act.sa_flags = SA_SIGINFO;
	act.sa_sigaction = handler;
	sigaction(SIGRTMIN+1,&act,NULL);
	sigfillset(&newmask);//阻塞所有信号
	sigprocmask(SIG_BLOCK,&newmask,&oldmask);//阻塞
	printf("阻塞开始\n");
	printf("处理中....\n");
	sleep(10);
	printf("处理结束...\n");
	printf("等待信号\n");
	sigsuspend(&oldmask);//设置信号掩码为调用程序原信号掩码即oldmask 返回后又变为newmask
	sigprocmask(SIG_UNBLOCK,&oldmask,NULL);//恢复
	printf("main end\n");
}

